package first;
import java.io.*;

public class ConnectBean {
    private String  username;
    private String  password;
    private String  postbox;
    private String  fname;
    private String  sname;
    private String  department;
    private String  object;
    private  String url;

    public ConnectBean(){}

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username=username;
    }

    public boolean Judge(String username){
        File fread = new File("Student.txt");
        int flag=0;
        try {
            Reader in =new FileReader(fread);
            BufferedReader bufferRead =new BufferedReader(in);
            String str=null;
            String[] massege;
            while((str=bufferRead.readLine())!=null){
                massege=str.split(",");
                if(massege[0].equals(username)){
                    flag=1;
                    break;
                }
            }
            bufferRead.close();
            in.close();
            if(flag==1){
                return true;
            }
            else return false;
        }
        catch(IOException e){
            System.out.println(e.toString());
        }


        if(flag==1) {
            return true;
        }
        else return false;
    }

    public void Build(String username){
        int flag=0;
        try {
            Writer out =new FileWriter("Student.txt",true);
            BufferedWriter bufferWrite =new BufferedWriter(out);
           // String str=username+","+"123456,"+"t3.jpg";
            String str=username+","+"123456"+","+""+","+""+","+""+","+""+","+""+","+"t3.jpg";
            bufferWrite.write(str);
            bufferWrite.newLine();
            flag=1;

            bufferWrite.close();
            out.close();
        }
        catch(IOException e){
            System.out.println(e.toString());
        }

    }

    public String  Connect(String username){
        boolean flag;
        flag=Judge(username);
        if(!flag){
            Build(username);
        }
        return username;
    }
}
